﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 实验二._2
{
    class Program
    {
        static void Main(string[] args)
        {
            Car car = new Car();
            Truck truck = new Truck();
            car.V = 100;
            truck.V = 100;
            Console.WriteLine("修改负重前：");
            car.Run(1000);
            truck.Run(1000);
            truck.Load = 100;
            Console.WriteLine("修改负重后：");
            car.Run(1000);
            truck.Run(1000);
            Console.ReadKey();
        }
    }
    public abstract class vehicle
    {
        private float v;

        public float V { get { return v; } set { v = value; } }
        public vehicle(float v)
        {
            this.v = v;
        }
        public vehicle()
        {
        }
        public virtual void Run(float d)
        {
            Console.WriteLine($"行驶{d}公里，使用{d / v}时间");
        }
    }//定义抽象交通工具类
    class Car : vehicle
    {
        public int passengers;
        public Car(float v, int pass)
        {
            V = v;
            passengers = pass;
        }
        public Car()
        {
        }

    }
    class Truck : vehicle
    {
        private float load;

        public float Load { get { return load; } set { load = value; } }
        public override void Run(float d)
        {
            Console.WriteLine($"卡车行驶{d}公里，使用{d / V * (1 + Load / 100)}时间");
        }

    }
}
